﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Windows.Media.Imaging;

namespace personalplaner.common.converters
{
	public class PrinterLocationConverter : IValueConverter
	{
		public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
		{
			var str = value as string;

			if (string.IsNullOrEmpty(str))
				return "Local";

			return str;
		}

		public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
		{
			return "";
		}
	}

	[ValueConversion(typeof(string), typeof(bool))]
	public class PrinterNameToImageConverter : IValueConverter
	{
		public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
		{
			var str = value as string;

			Uri uri = null;

			if (!string.IsNullOrEmpty(str))
			{
				if(str.StartsWith("\\\\"))
				uri = new Uri("pack://application:,,,/personalplaner.common;component/resources/images/Network-Printer.png");
			}

			if(uri==null)
				uri = new Uri("pack://application:,,,/personalplaner.common;component/resources/images/Hardware-Printer.png");

            return new BitmapImage(uri);

            //if ((value as string).Contains(@"\"))
            //{
				
            //    try
            //    {
            //        var d = new System.IO.DriveInfo(value as string);
            //        switch (d.DriveType)
            //        {
            //            case System.IO.DriveType.CDRom:
            //                uri = new Uri("pack://application:,,,/personalplaner.common;component/Resources/Images/Image.CDDrive.png");
            //                break;
            //            case System.IO.DriveType.Fixed:
            //            case System.IO.DriveType.NoRootDirectory:
            //            case System.IO.DriveType.Ram:
            //            case System.IO.DriveType.Unknown:
            //                uri = new Uri("pack://application:,,,/Sage200.X3Connect.Core;component/Resources/Images/Image.Diskdrive.png");
            //                break;
            //            case System.IO.DriveType.Network:
            //                uri = new Uri("pack://application:,,,/Sage200.X3Connect.Core;component/Resources/Images/Image.NetworkDrive.png");
            //                break;
            //            case System.IO.DriveType.Removable:
            //                uri = new Uri("pack://application:,,,/Sage200.X3Connect.Core;component/Resources/Images/Image.RemovableDrive.png");
            //                break;
            //        }
            //    }
            //    catch { }

            //    if (uri == null)
            //        uri = new Uri("pack://application:,,,/Sage200.X3Connect.Core;component/Resources/Images/Image.Diskdrive.png");
            //    BitmapImage source = new BitmapImage(uri);
            //    return source;
            //}
            //else
            //{
            //    //Uri uri = new Uri("pack://application:,,,/Resources/Images/folder.png");
            //    Uri uri = new Uri("pack://application:,,,/Sage200.X3Connect.Core;component/Resources/Images/Image.FolderDrive.png");
            //    BitmapImage source = new BitmapImage(uri);
            //    return source;
            //}
		}

		public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
		{
			throw new NotSupportedException("Cannot convert back");
		}
	}
}
